<?php 
namespace town\controller;

use town\model\User;
use town\base\Request;

/**
 * 获取用户信息
 */
class UserController
{

    /**
     * 用户登录
     */
    public function login(Request $req)
    {
    	$name = $req->val('name');
    	$pass = $req->val('passwd');
    	$user = new User();
    	$info = $user->login($name, $pass);
    	if (is_array($info)) {
            $_SESSION['userid'] = $info['id'];
            $_SESSION['user']   = $info;
    		return redirect('/back');
    	}
    	return view('back/login', ['msg'=>$info]);
    }


    /**
     * 用户注销
     */
    public function logout()
    {
        unset($_SESSION['userid']);
        unset($_SESSION['user']);

        return view('back/login', ['msg'=>'退出成功!']);
    }

}

